#*-*coding=utf-8*-
#file TemplateParser
#Provides smart interface to file

import os,re,sys
from model.File import *
from Errors import *


class TemplateParser(object):
    '''
    Main model class used to parse the template
    '''
    def __init__(self,path):
        '''
        Class constructor
        '''
        self._keywords = [] # storing all keywords contained by the file
        self._file = None
        try :
            self._file = File(path)
        except Exception :
            raise ParsingError("FileCantBeOpened")
    def parse(self):
        '''
        Main method of the parser. 
        Search all the occurences of keywords and return an array filled with that.
        '''
        kw = {"variables":None} 
        kw["variables"] = self._getKeywords()
        return kw
    def _getKeywords(self):
        '''
        Retrieve all the keywords of the file namely the contents of '{}' tags
        '''
        return re.findall(r"\{(.+?)\}",self._file.getContent(),re.DOTALL)
    def _getVariables(self):
        '''
        Retrieve all variables contained in the file
        '''
        pass
    
    

       
if __name__=="__main__":
    fp = TemplateParser("../test/test.tpl")
    print fp.parse()
